#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
Warning, this example is not complete
"""

__all__ = [u'ReaderQuad']

from plugins.mesher import MeshToolInterface
from plugins.mesher.meshformats import pyLotMesh, pyLotQuad
from pylot.core import hardbook

class ReaderQuad (MeshToolInterface):

  name = u'ReaderQuad'
  alias = u'pyLot Quad to pyLotmesh converter'
  tooltip = u'Create a pylotmesh from pylot-quad mesh'
  doc = u"""
  This tool convert a simple pylot quad mesh to pylotmesh.
  Parameters are passed as simple dictionnary.
  Available keys are :
    datatype : pylotmesh file format type
      - type : unicode string
      - allowed values : ASCII, binary
  """

  input_format = pyLotQuad
  output_format = pyLotMesh

  def _cmdGroupTransform (self, meshin, meshout, parameters):
    # compatibility between meshin, meshout and this tool checked by MeshToolInterface
    # _checkParameters yet called too !
    # so all parameters are OK here
    reader = unicode(hardbook(u'meshreaders', u'ReaderQuad'))
    meshin = unicode(meshin.path.abspath())
    meshout = unicode(meshout.path.abspath())
    datatype = parameters[datatype]

    cg = CommandGroup(self.name, self.alias)
    cg.addShellCmd(reader, [meshin, meshout, datatype])
    return cg

  @staticmethod
  def _newParameter(cls):
    params = {'datatype':'ASCII'}
    cls.checkParameters(params)
    return params

  @staticmethod
  def _checkParameters(cls, parameters):
    assert(isinstance(parameters, dict))
    assert(u'datatype' in parameters)
    assert(parameters[u'datatype'] in (u'ascii', u'binary'))
